package org.bigjava.user.util;

import lombok.Data;
import org.bigjava.bean.Comment;
import org.bigjava.bean.Reply;

import java.util.Comparator;

public class CommentOrReply implements Comparator {


    @Override
    public int compare(Object o1, Object o2) {
        Comment c1;
        Comment c2;
        Reply r1;
        Reply r2;
        if(o1 instanceof Comment){
            c1= (Comment) o1;
            if(o2 instanceof Reply){
                r1 = (Reply) o2;
                return c1.getDate().compareTo(r1.getDate());
            }else {
                c2 = (Comment) o2;
               return c1.getDate().compareTo(c2.getDate());
            }
        }else {
            r1 = (Reply) o1;
            if(o2 instanceof Reply){
                r2 = (Reply) o2;
                return r1.getDate().compareTo(r2.getDate());
            }else {
                c1 = (Comment) o2;
                return r1.getDate().compareTo(c1.getDate());
            }
        }
    }
}
